package com.chw.common.exception;

import com.chw.common.diy.CountException;
import com.chw.common.diy.ExceptionData;
import com.chw.common.diy.PassExction;
import com.chw.common.diy.TokenException;
import com.chw.common.returnData.ReturnData;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class Exceptoin {

    @ExceptionHandler(ParamExcption.class)
    public ReturnData chandleArithmeticException(Exception e){
        e.printStackTrace();
        return ReturnData.error(ExceptionData.PARAMEXCEPTION.getCODE(), ExceptionData.PARAMEXCEPTION.getMSG());
    }
    @ExceptionHandler(NameException.class)
    public ReturnData chandleNameException(Exception e){
        e.printStackTrace();
        return ReturnData.error(ExceptionData.NAMEEXCEPTION.getCODE(), ExceptionData.NAMEEXCEPTION.getMSG());
    }
    @ExceptionHandler(Exception.class)
    public ReturnData chandleException(Exception e){
        e.printStackTrace();
        return ReturnData.error(ExceptionData.SERVEREXCEPTION.getCODE(), ExceptionData.SERVEREXCEPTION.getMSG());
    }
    @ExceptionHandler(PassExction.class)
    public ReturnData chandlePassExction(Exception e){
        e.printStackTrace();
        return ReturnData.error(300, e.getMessage());
    }
    @ExceptionHandler(CountException.class)
    public ReturnData chandleCountException(Exception e){
        e.printStackTrace();
        return ReturnData.error(3000, e.getMessage());
    }
    @ExceptionHandler(TokenException.class)
    public ReturnData chandleTokenException(TokenException e){
        e.printStackTrace();
        return ReturnData.error(4004, e.getMessage());
    }
}
